<?php


namespace App\library\services;


use App\Models\Cities;

class CityService extends BaseServices
{
    /**
     * Author:YangXinPeng
     * 获得省份明细
     * @param $province
     * @return mixed
     */
   public static function getProvince($province)
   {
       if (empty($province)){
           return self::fail('参数错误');
       }
       $data = Cities::where(['pid'=>0,'name'=>$province])->first();
       $data && $data = $data->toArray();
       return $data;
   }

    /**
     * Author:YangXinPeng
     * 获取城市下对应区域
     * @param $provinceId
     * @return array
     */
   public static function getRgion($provinceId)
   {
       if (empty($provinceId)){
           return self::fail('参数错误');
       }
       $city = Cities::where('pid',$provinceId)->first();
       $city && $city = $city->toArray();
       $regions = Cities::where('pid',$city['id'])->get();
       $regions && $regions = $regions->toArray();
       return $regions;
   }

    /**
     * Author:YangXinPeng
     * 获取全部省会信息
     * @return array
     */
   public static function getProvinces()
   {
       $data = Cities::where('pid',0)->get();
       $data && $data = $data->toArray();
       return self::success('成功',$data);
   }

    /**
     * Author:YangXinPeng
     * 根据主键ID获取对应城市信息
     * @param $id
     * @return array
     */
   public static function getById($id)
   {
       $data = Cities::find($id);
       $data && $data = $data->toArray();
       return self::success('成功',$data);
   }

}
